package core

var (
	OK  = response(SUCCESS, "SUCCESS")
	Err = response(UNKNOWN, "不可预知错误") // 不可预知错误
)

// Response 结果返回机构体
type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

// WithMsg 自定义响应信息
func (res *Response) WithMsg(message string) Response {
	return Response{
		Code: res.Code,
		Msg:  message,
		Data: res.Data,
	}
}

// WithData 追加响应数据
func (res *Response) WithData(data any) Response {
	return Response{
		Code: res.Code,
		Msg:  res.Msg,
		Data: data,
	}
}

// 构造函数
func response(code int, msg string) *Response {
	return &Response{
		Code: code,
		Msg:  msg,
		Data: nil,
	}
}

func NewError(code int, msg string) *Response {
	return &Response{
		Code: code,
		Msg:  msg,
		Data: "",
	}
}
